import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { BaseItem } from "../common/BaseItem";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { Language } from "../../../../extend/language/Language";
import { TIntegralShopItemNew } from "../../../../Message/Db/Tables/TIntegralShopItemNew";
import { ItemData } from "../../resource/info/ItemData";
import { ColorConfig } from "../../resource/ColorConfig";
import { Cache } from "../../cache/Cache";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PulseSharedObject } from "../player/PulseSharedObject";
import { CheckBoxWin } from "../common/alertwins/CheckBoxWin";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
import { _shopId } from "../../../../this/_shopId";
type int = number;
//class IntegralShopRenderer
    
    export  class IntegralShopRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            this._bg = ObjCreate.createBg(0, 0, 173, 105, this, ImagesConst.RechargeBottom);
            this._nameTxt = ObjCreate.createGTextField("", 3, 2, 128, 20, this, GlobalStyle.textFormat1);
            this._propBg = ObjCreate.createBitmap(ImagesConst.PropBg, 3, 21, this);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(58, 58);
            this._baseItem.move(9, 27);
            this._baseItem.setAmountLabelPos(45, 40);
            this._baseItem.isDragAble = false;
            this._baseItem.isDropAble = false;
            addChild(this._baseItem);
            this._oldPriceTxt = ObjCreate.createGTextField("88888", 70, 25, 80, 20, this, GlobalStyle.textFormat1);
            this._oldPriceImg = new Object /* flash.display.Bitmap */();
            this._oldPriceImg.x = 140;
            this._oldPriceImg.y = 26;
            addChild(this._oldPriceImg);
            this._oldPriceImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Yuanbao_small);
            this._newPriceTxt = ObjCreate.createGTextField("125", 70, 45, 80, 20, this, GlobalStyle.textFormat6);
            this._newPriceImg = new Object /* flash.display.Bitmap */();
            this._newPriceImg.x = 140;
            this._newPriceImg.y = 46;
            addChild(this._newPriceImg);
            this._newPriceImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Yuanbao_small);
            this._btn = ObjCreate.createGButton(Language.getString(35048), 116, 65, 48, 23, this);
            this._btn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._numStepper = ObjCreate.createGNumericStepper(75, 65, 40, 22, this);
            this._redLine = new Object /* flash.display.Shape */();
            this._redLine.graphics.lineStyle(2, 16711680);
            this._redLine.graphics.moveTo(110, 30);
            this._redLine.graphics.lineTo(125, 40);
            this._redLine.cacheAsBitmap = true;
            addChild(this._redLine);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            super.data = arg1;
            if (arg1) 
            {
                this._shopType = arg1.shopType as int;
                this._shopId = arg1.shopId as int;
                this._itemInfo = arg1.item as TIntegralShopItemNew;
                loc1 = new ItemData(this._itemInfo.itemCode);
                if (loc1 && loc1.itemInfo && loc1.itemInfo.item) 
                {
                    loc2 = ColorConfig.instance.getItemColor(loc1.itemInfo.item.color).color;
                    this._baseItem.itemData = loc1;
                    this._name = "<font color=\'" + loc2 + "\'>" + loc1.itemInfo.item.name + "</font>";
                    this._nameTxt.htmlText = this._name;
                }
                if (this._itemInfo.priceOrigin == 0 || this._itemInfo.priceOrigin == this._itemInfo.price) 
                {
                    this._oldPriceTxt.text = "";
                    this._oldPriceImg.bitmapData = null;
                    this._redLine.visible = false;
                }
                else 
                {
                    this._oldPriceTxt.htmlText = Language.getString(35049) + this._itemInfo.priceOrigin;
                    this._oldPriceImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Yuanbao_small);
                    this._redLine.visible = true;
                }
                this._newPriceTxt.htmlText = Language.getString(35050) + this._itemInfo.price;
                this._btn.drawNow();
            }
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var gold: int;
            var onClickHandler: Function;

            var loc1;
            e = arg1;
            gold = Cache.instance.role.money.gold;
            if (gold < this._itemInfo.price) 
            {
                onClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GotoPay));
                        Alert.resetToDefault();
                    }
                    return;
                }
                Alert.show(Language.getString(30103), null, Alert.OK | Alert.CANCEL, null, onClickHandler);
            }
            else 
            {
                this.gotoBuyItem();
            }
            return;
        }

        /* internal  */gotoBuyItem(): void
        {
            var amount: int;
            var onClickHandler: Function;

            var loc1;
            amount = 0;
            amount = this._numStepper.value;
            if (PulseSharedObject.isTodayNotTips("IntegralShopBuyItem")) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.IntegralShopBuyItem, {"shopType": _shopId, "itemCode": this._itemInfo.itemCode, "amount": amount}));
            }
            else 
            {
                onClickHandler = (arg1: int, arg2: Boolean): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.IntegralShopBuyItem, {"shopType": _shopId, "itemCode": _itemInfo.itemCode, "amount": amount}));
                        Alert.resetToDefault();
                    }
                    if (arg2) 
                    {
                        PulseSharedObject.save("IntegralShopBuyItem", true);
                    }
                    return;
                }
                Alert.alertWinRenderer = CheckBoxWin;
                Alert.show(Language.getStringByParam(35051, this._itemInfo.price * amount, amount, this._name), null, Alert.OK | Alert.CANCEL, null, onClickHandler);
            }
            return;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_propBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: GTextFiled;

        /* internal */ /* var */_oldPriceTxt: GTextFiled;

        /* internal */ /* var */_oldPriceImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_newPriceTxt: GTextFiled;

        /* internal */ /* var */_newPriceImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btn: GButton;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_numStepper: GNumericStepper;

        /* internal */ /* var */_redLine: Object /* flash.display.Shape */;

        /* internal */ /* var */_itemInfo: TIntegralShopItemNew;

        /* internal */ /* var */_shopType: int;

        /* internal */ /* var */_shopId: int;

        /* internal */ /* var */_name: string="";
    }
